package com.pansoft.openplanet.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.efounder.chat.utils.LXGlideImageLoader;
import com.pansoft.openplanet.R;
import com.pansoft.openplanet.bean.RechargeMethodBean;

import java.util.List;

/**
 * Created by cimu on 2018/9/18.
 * 选择积分卡充值方式的Adapter
 */

public class AmountRechargeAdapter extends RecyclerView.Adapter<AmountRechargeAdapter.ViewHolder>{
    private Context mContext;
    private List<RechargeMethodBean> methodBeans;

    public AmountRechargeAdapter(Context context, List<RechargeMethodBean> rechargeMethodBean) {
        super();
        this.mContext = context;
        this.methodBeans = rechargeMethodBean;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_list_card_type, parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        if(position == 0){
            holder.topLine.setVisibility(View.GONE);
        }
        LXGlideImageLoader.getInstance().displayImage(mContext, holder.ivRechargePhoto,methodBeans.get(position).getBackGround());
        holder.tvRechargeMethod.setText(methodBeans.get(position).getName());
        LXGlideImageLoader.getInstance().displayImage(mContext, holder.ivPaySelectDown,methodBeans.get(position).getSelectDown());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(onClickListener != null){
                    onClickListener.onClick(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return methodBeans.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private LinearLayout llSelectPayFor;
        private ImageView ivRechargePhoto, ivPaySelectDown;
        private TextView tvRechargeMethod;
        private View topLine;

        public ViewHolder(View itemView) {
            super(itemView);
            llSelectPayFor = itemView.findViewById(R.id.ll_select_pay_for);
            ivRechargePhoto = itemView.findViewById(R.id.iv_recharge_photo);
            ivPaySelectDown = itemView.findViewById(R.id.iv_pay_select_down);
            tvRechargeMethod = itemView.findViewById(R.id.tv_recharge_method);
            topLine = itemView.findViewById(R.id.top_line);
        }
    }

    private OnClickListener onClickListener;

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface OnClickListener {
        void onClick(int position);
    }
}

